package com.sen.rbac.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sen.rbac.model.SysRole;
import com.sen.rbac.model.SysRoleAccount;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author esjiang
 */
public interface SysRoleAccountDao extends BaseMapper<SysRoleAccount> {

    /**
     * 查询账户所有的角色
     * @param userName
     * @return
     */
    @Select(value = "select * from sys_role role left join sys_role_account roleAccount on role.code = roleAccount.role_code where roleAccount.user_name=#{userName}")
    List<SysRole> findRolesByUserName(String userName) ;

    /**
     * 查询账户所有的角色
     * @param userName
     * @param tenantCode
     * @return
     */
    @Select(value = "select * from sys_role role left join sys_role_account roleAccount on role.code = roleAccount.role_code " +
            "where roleAccount.user_name=#{userName} and role.tenant_code=#{tenantCode}")
    List<SysRole> findRolesByUserNameTenantCode(@Param("userName") String userName, @Param("tenantCode") String tenantCode) ;
}